/*
 * Copyright 2007 Xplayat, S.L. All rights reserved.
 * Propiedad de Xplayat. 
 */
package facelets.component;

import javax.faces.component.UIOutput;

import org.apache.myfaces.custom.column.HtmlSimpleColumn;

import com.sun.facelets.FaceletContext;
import com.sun.facelets.tag.TagAttribute;
import com.sun.facelets.tag.jsf.ComponentConfig;
import com.sun.facelets.tag.jsf.html.HtmlComponentHandler;

/**
 * @author nachoe
 *
 */
public class ColumnComponentHandler extends HtmlComponentHandler {
	
	private final TagAttribute label;
	
	public ColumnComponentHandler(ComponentConfig tagConfig) {
		super(tagConfig);
		label = getAttribute("label");
	}
	
	/* (non-Javadoc)
	 * @see com.sun.facelets.tag.MetaTagHandler#setAttributes(com.sun.facelets.FaceletContext, java.lang.Object)
	 */
	public void setAttributes(FaceletContext ctx, Object instance) {
		
		if ( label!=null && label.getValue()!=null) {
			UIOutput f = (UIOutput)
			ctx.getFacesContext().getApplication().createComponent(UIOutput.COMPONENT_TYPE);
			f.setValue(label.getValue(ctx));
			((HtmlSimpleColumn) instance).getFacets().put("header", f);
		}
		
		super.setAttributes(ctx, instance);
	}
}
